
#include "enemyword.h"

enemyword::enemyword(const QString &word,const QPoint &firePos,const QPoint &pos,QObject *parent)
    : QObject{parent}
{
    this->firePos = firePos;
    curPos = pos;
    this->word = word;
    curIndex = 0;
    destroyed = false;

    half_w = word.size()*10 + 5;
    half_h = 20;



}
int enemyword::getHalfW(void){

    return half_w;
}
int enemyword::getHalfH(void){

    return half_h;
}


bool enemyword::appendBall(const QString &c){
    bool ret;
    //c是正确的就添加ball，否则不添加；

    if(c == word[curIndex]){
        curIndex++;
        if(curIndex == word.size()){
            destroyed = true;
            curIndex = 0;
            ret = false;

        }else{
            ret = true;
        }

    }
    else{
        curIndex = 0;
        return false;

    }


    cannonball *ball = new cannonball(firePos);
    for(int i = 0;i<8;i++){
        ball->ballMove(curPos);}

    ballList.append(ball);



    return ret;
}
void enemyword::ballsApproach(void){
    for(int i=0;i<ballList.size();i++){
        ballList[i]->ballMove(curPos);
        if(ballList[i]->getActive() == false){
            cannonball *ball = ballList[i];
            ballList.removeAt(i);
            delete ball;
        }


    }


}

QList<cannonball *> * enemyword::getBallList(void){
    return &ballList;


}
const QPoint & enemyword::getPos(void){
    return curPos;


}
void enemyword::setPos(const QPoint &pos){
    curPos = pos;

}

const QString &enemyword::getWord(void){
    return word;



}
int enemyword::getCureIndex(void){
    return curIndex;

}
bool enemyword::getDestroyed(void){
    return destroyed;

}

